package game.asset
{
	import engine.asset.*;
	import engine.core.*;
	import engine.graphics.shader.*;
	import engine.loaders.*;
	import engine.math.*;
	import game.actor.*;
	
	public class RxAssetCharacter extends RxAssetModel
	{
		private var m_globalScale:Number;
		private var m_attachmentScale:Number;
		private var m_partsAssembler:RxCharacterPartsAssembler;
		private static var s_type:int;
		
		public function RxAssetCharacter(shader:RxShaderFamilyBase)
		{
			super(shader, s_type);
			this.m_globalScale = 1;
			this.m_attachmentScale = 1;
			this.m_partsAssembler = null;
		}
		
		public static function Initialize() : void
		{
			s_type = RxAsset.RegisterType("character", CreateFromXML);
		}
		
		public static function CreateFromXML(param1:XML, param2:String) : RxAssetCharacter
		{
			var _loc_17:RxCharacterPartsTable = null;
			var _loc_18:RxVector4 = null;
			var _loc_19:XMLList = null;
			var _loc_20:XMLList = null;
			var _loc_21:XML = null;
			var _loc_22:String = null;
			var _loc_23:String = null;
			var _loc_24:String = null;
			var _loc_25:String = null;
			var _loc_26:XML = null;
			var _loc_3:* = param1.@name;
			var _loc_4:* = param1.@url;
			var _loc_5:* = param1.@mesh;
			var _loc_6:* = param1.@skel;
			var _loc_7:* = param1.@anim;
			var _loc_8:* = param1.@bitmap;
			var _loc_9:* = param1.@shader;
			var _loc_10:* = s_shaderFamilyManager.GetShaderFamily(_loc_9);
			var _loc_11:* = param1.@globalScale;
			var _loc_12:* = param1.@globalScale != "" ? (Number(_loc_11)) : (1);
			var _loc_13:* = param1.@attachScale;
			var _loc_14:* = param1.@attachScale != "" ? (Number(_loc_13)) : (1);
			var _loc_15:RxCharacterPartsAssembler = null;
			if (_loc_4 == "")
			{
				_loc_17 = RxCharacter.GetPartsTable();
				_loc_17.SetShaderFamily(_loc_10);
				_loc_15 = new RxCharacterPartsAssembler(_loc_17);
				_loc_15.SetSkeletonName(_loc_6);
				if (_loc_7 != "")
				{
					_loc_15.AddAnimationName(_loc_7);
				}
				_loc_18 = new RxVector4(1, 1, 1, 1);
				_loc_19 = param1.anim;
				if (_loc_19.length() > 0)
				{
					for each (_loc_21 in _loc_19)
					{
						
						_loc_7 = _loc_21.@name;
						if (_loc_7 != "")
						{
							_loc_15.AddAnimationName(_loc_7);
						}
					}
				}
				_loc_20 = param1.slot;
				if (_loc_20.length() > 0)
				{
					for each (_loc_26 in _loc_20)
					{
						
						_loc_22 = _loc_26.@name;
						_loc_23 = _loc_26.@mesh;
						_loc_24 = _loc_26.@bitmap;
						_loc_25 = _loc_26.@color;
						if (RxCharacterPartsAssembler.IsSlotNameValid(_loc_22))
						{
							_loc_18.x = 1;
							_loc_18.y = 1;
							_loc_18.z = 1;
							_loc_18.w = 1;
							if (_loc_25 != "")
							{
								_loc_18.CopyFromString(_loc_25);
							}
							_loc_15.SetSlotDefinition(new RxCharacterSlotDefinition(_loc_22, _loc_23, _loc_24, _loc_18));
						}
					}
				}
				else
				{
					_loc_15.SetSlotDefinition(new RxCharacterSlotDefinition(RxCharacterPartsAssembler.SLOT_BODY, _loc_5, _loc_8, _loc_18));
				}
			}
			var _loc_16:* = Create(_loc_4, _loc_3, _loc_10);
			Create(_loc_4, _loc_3, _loc_10).m_globalScale = _loc_12;
			_loc_16.m_attachmentScale = _loc_14;
			_loc_16.m_partsAssembler = _loc_15;
			return _loc_16;
		}
		
		public static function Create(param1:String, param2:String, param3:RxShaderFamilyBase) : RxAssetCharacter
		{
			var _loc_4:RxAssetCharacter = null;
			if (param1 != "")
			{
				_loc_4 = GetByURL(param1);
				if (_loc_4 != null)
				{
					return _loc_4;
				}
			}
			_loc_4 = new RxAssetCharacter(param3);
			_loc_4.SetURL(param1);
			_loc_4.SetName(param2);
			return _loc_4;
		}
		
		public static function GetByURL(param1:String) : RxAssetCharacter
		{
			return RxAssetCharacter(_getByURL(param1, s_type));
		}
	}
}